import { defineStore } from 'pinia';
import { store } from '../index';
import { useCache } from '@/hooks/useCache';

const { wsCache } = useCache();
interface LocaleState {
	currentLocale: any
	localeMap: any
}

export const useLocaleStore = defineStore('locales', {
	state: (): LocaleState => {
		return {
			currentLocale: {
				lang: wsCache.get('lang') || 'zh-CN',
				elLocale: 'zh-CN'
			},
			// 多语言
			localeMap: [
				{
					lang: 'zh-CN',
					name: '简体中文'
				},
				{
					lang: 'en',
					name: 'English'
				}
			]
		};
	},
	getters: {
		getCurrentLocale(state): any {
			return state.currentLocale;
		},
		getLocaleMap(state): any {
			return state.localeMap;
		}
	},
	actions: {
		setCurrentLocale(localeMap: any) {
			wsCache.set('lang', localeMap?.lang);
		}
	}
});

export const useLocaleStoreWithOut = () => {
	return useLocaleStore(store);
};
